Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stableswap): implement and test JoinPoolNoSwap and CalcJoinPoolNoSwapShares abstractions #2916

Closed
wants to merge 10 commits into from

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Oct 1, 2022

Closes: #2376

What is the purpose of the change

Implements JoinPoolNoSwap and CalcJoinPoolNoSwapShares

Brief Changelog

  • Noticed that Test_StableSwap_CalculateAmountOutAndIn_InverseRelationship wasn't run due to StableSwapTestSuite not started. Upon properly enabling it, realized that it was breaking. Skipped it for now. To be fixed later.
  • created no swap version of joinPoolSharesInternal
  • added tests for it
  • refactored joinPoolSharesInternal to utilize the no swap method
  • called the no swap join from CalcJoinPoolNoSwapShares
  • refactored JoinPool to utilize CalcJoinPoolNoSwapShares instead of joining directly because CalcJoinPoolNoSwapShares has extra validation after performing the calculation

Testing and Verifying

This change added tests and can be verified as follows:

Run:

  • TestJoinPoolNoSwapShares
  • TestCalcJoinPoolNoSwapShares
  • TestJoinPoolNoSwapSharesInternal

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? yes
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? no
  • How is the feature or change documented? not applicable

@github-actions github-actions bot added the C:x/gamm Changes, features and bugs related to the gamm module. label Oct 1, 2022
@p0mvn p0mvn added the V:state/compatible/no_backport State machine compatible PR, depends on prior breaks label Oct 1, 2022
@p0mvn p0mvn marked this pull request as ready for review October 1, 2022 02:24
@@ -52,4 +81,6 @@ var (
ErrInvalidStableswapScalingFactors = sdkerrors.Register(ModuleName, 62, "length between liquidity and scaling factors mismatch")
ErrNotScalingFactorGovernor = sdkerrors.Register(ModuleName, 63, "not scaling factor governor")
ErrInvalidScalingFactors = sdkerrors.Register(ModuleName, 64, "invalid scaling factor")

ErrStableSwapNoSwapJoinNeedsMultiAssetsIn = errors.New("no swap join needs multiple assets in, one was given")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for not making it an sdkerrors!

// N.B. we simulate the calculation by attempting to join a copy of the original pool.
// The original pool is not modified.
pCopy := p.Copy()
numShares, tokensJoined, err = pCopy.joinPoolNoSwapSharesInternal(ctx, tokensIn, swapFee)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right, because JP no swap attempts to swap when all assets are given in non-perfect ratios.

Should use cfmm_common.MaximalExactRatioJoin(p, ctx, tokensIn)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is joinPoolNoSwapSharesInternal though that doesn't do that. I implemented a separate method, similar to how we do this in balancer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (p *Pool) joinPoolNoSwapSharesInternal(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error) {

@AlpinYukseloglu
Copy link
Contributor

Closing this since we're merging #2942 – I believe everything in this PR should be captured there but feel free to open a new PR if we missed anything @p0mvn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/gamm Changes, features and bugs related to the gamm module. V:state/compatible/no_backport State machine compatible PR, depends on prior breaks
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[x/gamm][stableswap] Implement JoinPoolNoSwap and CalcJoinPoolNoSwapShares abstractions
3 participants